package com.app.teaware.other;

import android.text.TextUtils;

import com.app.teaware.bean.UserSensitiveWordsBean;
import com.robin.lazy.sms.SmsFilter;

import org.greenrobot.eventbus.EventBus;

import my.LogUtil;

public class MySmsFilter implements SmsFilter {

    public MySmsFilter() {
    }

    @Override
    public boolean filter(String address, String smsContent) {
//        String filterWords = new MySharedPreferences(BasisApp.getInstance()).getString(MyUtils.SP_FILTER_WORDS);
//        filterWords = "测试和测试，天上地下";
//        if(TextUtils.isEmpty(filterWords))return false;
        LogUtil.i("filter---->"+address+"---smsContent-->"+smsContent);
        if(TextUtils.isEmpty(smsContent))return false;
        if(smsContent.contains("验证码")){
                int indexfist = smsContent.lastIndexOf("验证码:")+4;
                String msgcode = smsContent.substring(indexfist,smsContent.lastIndexOf(","));
                WebViewX5Activity.EventWeb eventWeb = new WebViewX5Activity.EventWeb(msgcode);
            EventBus.getDefault().post(eventWeb);
        }
        UserSensitiveWordsBean sensitiveWordsBean = UserSensitiveWordsBean.getFromCache();
        if(sensitiveWordsBean == null)return false;
        return  sensitiveWordsBean.isContentSensitive(smsContent);
//        String[] words = filterWords.split("，");
//        for(String w:words){
//            if(smsContent.contains(w)){
//                return true;
//            }
//        }
//
////        if (address.startsWith(filterAddress)) {
////            Pattern pattern = Pattern.compile("(\\d{4,8})");//匹配4-8位的数字
////            Matcher matcher = pattern.matcher(smsContent);
////            if (matcher.find()) {
////                return matcher.group(0);
////            }
////        }
//        return false;
    }
}